﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Remove
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void btnChooseFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openTxtFileDialog = new OpenFileDialog();
            //openTxtFileDialog.InitialDirectory = "c:\\";
            openTxtFileDialog.Filter = "txt files (*.txt)|*.txt";
            //openTxtFileDialog.FilterIndex = 2;
            //openTxtFileDialog.RestoreDirectory = true;

            HashSet<string> set = new HashSet<string>();
            if (openTxtFileDialog.ShowDialog() != DialogResult.OK) return;

            string fileName = openTxtFileDialog.FileName;
            using (StreamReader sr = File.OpenText(fileName))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                    set.Add(s);
            }
            using (StreamWriter sw = File.CreateText(fileName))
                foreach (var item in set)
                    sw.WriteLine(item);
        }
    }
}
